<template>
    <div style="width: 600px;">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">
    <h1 style="font-size:26px;text-align: center;margin-bottom: 20px;">原告</h1>
    <div>
        <el-form-item label="原告" prop="yuan_name">
            <el-input v-model="ruleForm.yuan_name"></el-input>
        </el-form-item>
        <el-form-item label="住址" prop="yuan_site">
            <el-input v-model="ruleForm.yuan_site"></el-input>
        </el-form-item>
        <el-form-item label="是否存在法定代表人" prop="representative">
            <el-radio-group v-model="ruleForm.representative" @change="changeRe">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
            </el-radio-group>
        </el-form-item>
        <div v-if="one_f">
            <el-form-item label="法定代表人" prop="fading_name_1">
                <el-input v-model="ruleForm.fading_name_1"></el-input>
            </el-form-item>
            <el-form-item label="统一社会信用代码" prop="total_code_1">
                <el-input v-model="ruleForm.total_code_1"></el-input>
            </el-form-item>
        </div>
        <div v-if="two_f">
            <el-form-item label="民族" prop="nation_1">
                <el-input v-model="ruleForm.nation_1"></el-input>
            </el-form-item>
            <el-form-item label="性别" prop="gender_1">
                <el-input v-model="ruleForm.gender_1"></el-input>
            </el-form-item>
            <el-form-item label="出生日期" required>
                <el-col :span="11">
                    <el-form-item prop="date1">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-form-item>
            <el-form-item label="身份证号" prop="id_num_1">
                <el-input v-model="ruleForm.id_num_1"></el-input>
            </el-form-item>
        </div>
    </div>
    <h1 style="font-size:26px;text-align: center;margin-bottom: 20px;">委托诉讼代理人</h1>
    <el-form-item label="委托诉讼代理人" prop="lawyer">
        <el-input v-model="ruleForm.lawyer"></el-input>
    </el-form-item>
    <h1 style="font-size:26px;text-align: center;margin-bottom: 20px;">被告</h1>
    <div>
        <el-form-item label="被告" prop="bei_name">
            <el-input v-model="ruleForm.bei_name"></el-input>
        </el-form-item>
        <el-form-item label="住址" prop="bei_site">
            <el-input v-model="ruleForm.bei_site"></el-input>
        </el-form-item>
        <el-form-item label="是否存在法定代表人" prop="representativeTwo">
            <el-radio-group v-model="ruleForm.representativeTwo" @change="changeReTwo">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
            </el-radio-group>
        </el-form-item>
        <div v-if="three_f">
            <el-form-item label="法定代表人" prop="fading_name_2">
                <el-input v-model="ruleForm.fading_name_2"></el-input>
            </el-form-item>
            <el-form-item label="统一社会信用代码" prop="total_code_2">
                <el-input v-model="ruleForm.total_code_2"></el-input>
            </el-form-item>
        </div>
        <div v-if="four_f">
            <el-form-item label="民族" prop="nation_2">
                <el-input v-model="ruleForm.nation_2"></el-input>
            </el-form-item>
            <el-form-item label="性别" prop="gender_2">
                <el-input v-model="ruleForm.gender_2"></el-input>
            </el-form-item>
            <el-form-item label="出生日期" required>
                <el-col :span="11">
                    <el-form-item prop="date2">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date2" style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-form-item>
            <el-form-item label="身份证号" prop="id_num_2">
                <el-input v-model="ruleForm.id_num_2"></el-input>
            </el-form-item>
        </div>
    </div>
    <el-form-item>
        <el-button type="primary" @click="submitForm()">立即创建</el-button>
        <!--<el-button @click="resetForm('ruleForm')">重置</el-button>-->
    </el-form-item>
</el-form>
    </div>
</template>
<script>
	import { AddInfo } from "../../common/js/api";
  export default {
    data() {
      return {
        one_f: false,
        two_f: false,
        three_f: false,
        four_f: false,
        ruleForm: {
          yuan_name: '', // 原告名字
          yuan_site: '', // 原告地址
          fading_name_1: '', // 法定代表人名字
          total_code_1: '', // 统一信用代码
          nation_1: '', // 民族
          gender_1: '', // 性别
          date1: '', // 日期
          id_num_1: '', // 身份证号
          bei_name: '', // 被告名字
          bei_site: '', // 被告地址
          fading_name_2: '', // 法定代表人名字
          total_code_2: '', // 统一信用代码
          nation_2: '', // 民族
          gender_2: '', // 性别
          id_num_2: '', // 身份证号
          lawyer:'', // 委托书上代理人
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: '',
          representative: '', // 是否存在法定代表人1
          representativeTwo: '', // 是否存在法定代表人2
        },
        /*rules: {
          name: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '请选择活动区域', trigger: 'change' }
          ],
          date1: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
          date2: [
            { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
          ],
          type: [
            { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
          ],
          representative: [
            { required: true, message: '请选择是否存在法定代表人', trigger: 'change' }
          ],
          desc: [
            { required: true, message: '请填写活动形式', trigger: 'blur' }
          ]
        }*/
      };
    },
    methods: {
      submitForm() {
        let data = {
          real_name: this.ruleForm.yuan_name,
          addr: this.ruleForm.yuan_site,
          is_la: this.ruleForm.representative,
          legal_agent: this.ruleForm.fading_name_1,
          social_code: this.ruleForm.total_code_1,
          nationality: this.ruleForm.nation_1,
          sex: this.ruleForm.gender_1,
          birth: this.ruleForm.date1,
          id_no: this.ruleForm.id_num_1,
          defendant: this.ruleForm.bei_name,
          deft_addr: this.ruleForm.bei_site,
          deft_is_la: this.ruleForm.representativeTwo,
          deft_legal_agent: this.ruleForm.fading_name_2,
          deft_social_code: this.ruleForm.total_code_2,
          deft_nationality: this.ruleForm.nation_2,
          deft_sex: this.ruleForm.gender_2,
          deft_birth: this.ruleForm.date2,
          deft_id_no: this.ruleForm.id_num_2,
          lawyer: this.ruleForm.lawyer
        }
        AddInfo(data).then(res => {
          console.log(res)
          if(res.data.code === 0){
            this.$message({
              message: '添加成功',
              type: 'success'
            });
          }
          this.$router.push({ path: '/plaintList' });
        })
      },

      changeRe(){
        if(this.ruleForm.representative) {
          this.one_f = true;
          this.two_f = false;
          this.ruleForm.nation_1 = '';
          this.ruleForm.gender_1 = '';
          this.ruleForm.data1 = '';
          this.ruleForm.id_num_1 = '';
        }else {
          this.one_f = false;
          this.two_f = true;
          this.ruleForm.total_code_1 = '';
          this.ruleForm.fading_name_1 = '';
        }
      },
      changeReTwo() {
        if(this.ruleForm.representativeTwo) {
          this.three_f = true;
          this.four_f = false;
          this.ruleForm.nation_2 = '';
          this.ruleForm.gender_2 = '';
          this.ruleForm.data2 = '';
          this.ruleForm.id_num_2 = '';
        }else {
          this.three_f = false;
          this.four_f = true;
          this.ruleForm.total_code_2 = '';
          this.ruleForm.fading_name_2 = '';
        }
      }
    }
  }
</script>
